#ifndef __SOC_COMMON_DEF_H__
#define __SOC_COMMON_DEF_H__


#include "target_def.h"
#include "soc_cfg.h"


#define SET_BIT(v, bit)  v |= (0x01 << bit)
#define CLR_BIT(v, bit)  v &= ~(0x01 << bit)
#define OP_BIT(v, bit, bitVal)  do{ \
  if(bitVal)\
    SET_BIT(v, bit); \
  else\ 
    CLR_BIT(v, bit);\
}while(0)

#define IS_BIT_SET(v, bit)  ((v & (0x01 << bit)) != 0)
#define IS_BIT_CLR(v, bit)  ((v & (0x01 << bit)) == 0)

#define GET_BIT(v, bit)  ((v >> bit) & 0x01)

#define UNUSED(p)  (void)p

//私有调用
#define PRIVATE_CALL 

//SYSTEM
typedef enum
{
  S_SleepGPIOWakeUp = 0,
  S_SleepTimeoutWakeUp
}SOC_SleepMode_t;

//GPIO
#define S_PORT_PIN_DEF(port, pin)  ((uint16_t)((port << 8) | pin))

typedef enum 
{
  S_GPIO_Mode_AIN = 0,     //模拟输入
  S_GPIO_Mode_IN_FLOATING, //浮空输入
  S_GPIO_Mode_IN_PULLDOWN, //下拉输入
  S_GPIO_Mode_IN_PULLUP,   //上拉输入
  S_GPIO_Mode_Out_OD,      //开漏输出
  S_GPIO_Mode_Out_PP,      //推挽输出
}SOC_GpioMode_t;

typedef enum 
{
  S_PortA = 0, S_P0 = 0,
  S_PortB = 1, S_P1 = 1,
  S_PortC = 2, S_P2 = 2,
  S_PortD = 3, S_P3 = 3,
  S_PortE = 4, S_P4 = 4,
  S_PortF = 5, S_P5 = 5,
  S_PortG = 6, S_P6 = 6,
  S_PortH = 7, S_P7 = 7,
  S_PortI = 8, S_P8 = 8,
  S_PortJ = 9, S_P9 = 9,
  S_PortK = 10, S_P10 = 10,
  S_PortL = 11, S_P11 = 11,
  S_PortM = 12, S_P12 = 12,
  S_PortN = 13, S_P13 = 13,
}SOC_GpioPort_t;

typedef enum
{
  S_GPIO_IT_RISING = 0,
  S_GPIO_IT_FALLING,
  S_GPIO_IT_BOTH_EDGE,

  //现代MCU比较少用
  S_GPIO_IT_LowLevel,
  S_GPIO_IT_HighLevel,
}SOC_GpioItMode_t;


//UART
typedef enum 
{
  S_UART0 = 0,
  S_UART1,
  S_UART2,
  S_UART3,
  S_UART4,
  S_UART5,
  S_UART6,
  S_UART7,
  S_UART8,
  S_UART9,
  S_UART10,
  S_UART11,
  S_UART12,
  S_UART13,
  S_UART14,
  S_UART15,
  S_UART16,
}SOC_UartNo_t;

//TIMER
typedef enum
{
  S_TIMER_0 = 0,
  S_TIMER_1,
  S_TIMER_2,
  S_TIMER_3,
  S_TIMER_4,
  S_TIMER_5,
  S_TIMER_6,
  S_TIMER_7,
  S_TIMER_8,
  S_TIMER_9,
  S_TIMER_10,
  S_TIMER_11,
  S_TIMER_12,
  S_TIMER_13,
  S_TIMER_14,
  S_TIMER_15,
  S_TIMER_16,
}SOC_TimerNo_t;

typedef void (*TIMEROUT)(void *sender);
typedef struct  
{
  SOC_TimerNo_t No;
  int Ms;
  TIMEROUT cb;
}SOC_Timer_t;


//ADC
typedef enum{
  S_ADC_0 = 0,
  S_ADC_1,
  S_ADC_2,
  S_ADC_3,
  S_ADC_4
}SOC_AdcNo_t;


//I2C
typedef enum 
{
  S_I2C_0 = 0,
  S_I2C_1,
  S_I2C_2,
  S_I2C_3,
  S_I2C_4,
  S_I2C_5,
  S_I2C_6,
  S_I2C_7,
}SOC_I2CNo_t;

typedef enum
{
  S_I2C_Master = 0,
  S_I2C_Slave
}SOC_I2CMode_t;

typedef struct SOC_I2CDev_e
{
  SOC_I2CNo_t no;
  uint8_t slaveWAddr;
  uint8_t slaveRAddr;
  
  uint8_t regAddrByte;
}SOC_I2CDev_t;

typedef void (*SOC_IT_CALLBACK_NO_PARAMS)(void);
typedef void (*SOC_IT_CALLBACK)(int no);
typedef void (*SOC_IT_CALLBACK_UART)(int no, unsigned char  b);
typedef void (*SOC_GPIO_IT_CALLBACK)(SOC_GpioPort_t port, int pin);


#endif 
